package gold.contest;

import gold.utils.InputUtil;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC6076 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minimumLines(int[][] stockPrices) {
            if (stockPrices.length <= 2) return stockPrices.length - 1;
            Arrays.sort(stockPrices, new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o1[0] - o2[0];
                }
            });

            int cnt = 1;
            for (int i = 2; i < stockPrices.length; i++) {
                if (1L * (stockPrices[i][1] - stockPrices[i - 1][1]) * (stockPrices[i - 1][0] - stockPrices[i - 2][0]) ==
                        1L * (stockPrices[i - 1][1] - stockPrices[i - 2][1]) * (stockPrices[i][0] - stockPrices[i - 1][0])) {
                    continue;
                } else cnt++;
            }

            return cnt;
        }
    }

    public void run() {
        System.out.println(new Solution().minimumLines(InputUtil.toDoubleIntegerArray("[[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]")));
        System.out.println(new Solution().minimumLines(InputUtil.toDoubleIntegerArray("[[3,4],[1,2],[7,8],[2,3]]")));
        System.out.println(new Solution().minimumLines(InputUtil.toDoubleIntegerArray("[[72,98],[62,27],[32,7],[71,4],[25,19],[91,30],[52,73],[10,9],[99,71],[47,22],[19,30],[80,63],[18,15],[48,17],[77,16],[46,27],[66,87],[55,84],[65,38],[30,9],[50,42],[100,60],[75,73],[98,53],[22,80],[41,61],[37,47],[95,8],[51,81],[78,79],[57,95]]")));
    }

    public static void main(String[] args) throws Exception {
        LC6076 an = new LC6076();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
